package com.lihao.sam.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lihao.sam.dao.RepairStatisticsDao;
import com.lihao.sam.entity.RepairStatistics;
import com.lihao.sam.service.intf.RepairStatisticsService;
import com.lihao.sam.vo.PageVo;
import com.lihao.sam.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author Qinheyun
 * @Description:TODO
 */
@Service
public class RepairStatisticsServiceImpl implements RepairStatisticsService {
    @Resource
    private RepairStatisticsDao dao;


    @Override
    public R add(RepairStatistics repairStatistics) {
        if (dao.add(repairStatistics)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(RepairStatistics repairStatistics) {
        if (dao.update(repairStatistics)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R del(int id) {
        if (dao.del(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageVo all(String address, String building, int page, int limit) {
        //开启分页
        PageHelper.startPage(page,limit);
        //执行查询
        PageInfo<RepairStatistics> pageInfo = new PageInfo<>(dao.all(address,building));
        //返回查询数据和总条数
        return PageVo.ok(pageInfo.getTotal(),pageInfo.getList());
    }
}
